import themeMixin from '@/mixins/theme'
import menuMixin from '@/mixins/menu'
import Scene from 'Comps/Scene/app'
import {
  filterMenu,
  handleCustomMenu,
  handleSystemMenu
} from '@/utils/menu'

export default {
  name: 'menuBar',
  mixins: [themeMixin, menuMixin],
  components: {
    Scene
  },
  data() {
    return {
      homeFlag: $globalconfig.HomeFlag,
      curIndex: 0,
      isShowSubmenu: false
    }
  },
  async mounted() {
    this.menuDataList = await filterMenu(this.$CONFIG.defMenu)
  },
  computed: {
    getNavMenu() {
      if(this.menuData && this.menuData.navmenu.length) {
        return this.menuData.navmenu
      }
    }
  },
  methods: {
    showBottomMenu() {
      this.formatActions(this.getBottomMenu, this.handleBtMenu)
      this.handleSheet()
    },
    goHome() {
      if (window.navigator.userAgent.toLowerCase().indexOf('micromessenger') == -1) {
        window.location.href = $globalconfig.URLS.HOME
      }else {
        wx.miniProgram.getEnv(res => {
          if (res.miniprogram) {
            wx.miniProgram.switchTab({url: '/pages/index/index'})
          } else {
            window.location.href = $globalconfig.URLS.HOME
          }
        })
      }
    },
    hideSubMenu() {
      this.isShowSubmenu = false
    },
    handleNavMenu(item, index) {
      if(item.children && item.children.length) {
        if(index == this.curIndex) {

          this.isShowSubmenu = !this.isShowSubmenu
        } else {
          this.isShowSubmenu = true
        }
      } else {
        this.handleSubMenu(item)
      }
      this.curIndex = index
    },
    handleSubMenu(item) {
      this.isShowSubmenu = false
      handleCustomMenu(item)
    }
  }
}